<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
<style>
  body{
	text-align:center;
  }
  #map_canvas{
	margin: 20px auto;
	border: 1px dashed #C0C0C0;
	width: 800px;
	height: 500px;
  }
	#geocode{
		position:absolute;
		left:10px;
		top:10px;
		width:250px;
		background-color:yellow;
	}
</style>
<!-- 
	位置搜索请求，首先需要在加载地图js时加载地址库，将libraries=places加载进来，
	然后要使用service = new google.maps.places.PlacesService(map)和service.search(request, callback)
	两句代码来查找与之相关的地点，需要查找的位置跟request的types有关。
-->
<script type="text/javascript">
  //将变量设置为全局变量方便方法调用
  var map, service;
	var infowindow = new google.maps.InfoWindow();

  function initialize() {
		geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(30.33508, 114.17211);
    var myOptions = {
      zoom: 10,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  }
		
	function codeLatLng() {
		var input = document.getElementById("latlngAddress").value;
		var latlngStr = input.split(",",2);
		var lat = parseFloat(latlngStr[0]);
		var lng = parseFloat(latlngStr[1]);
		var latlng = new google.maps.LatLng(lat, lng);
		var request = {
			location: latlng,
			radius: '500',
			types: ['school','store','bus_station']
		};
		service = new google.maps.places.PlacesService(map);
		service.search(request, callback);
	}

	//回调函数
	function callback(results, status) {
		if (status == google.maps.places.PlacesServiceStatus.OK) {
			for (var i = 0; i < results.length; i++) {
				var place = results[i];
				createMarker(results[i]); 
			}
		}
	}

	function createMarker(place) {
    var placeLoc = place.geometry.location;
		var marker = new google.maps.Marker({
			map: map,
			position: place.geometry.location
		});

		google.maps.event.addListener(marker, 'mouseover', function() {
			infowindow.setContent(place.name);
			infowindow.open(map, this);
		});
  }

</script>
</head>
<body onload="initialize()">
		<div id="geocode">请输入经纬度（用逗号隔开）：
    <input id="latlngAddress" type="text" value="30.51508, 114.36211">
    <input type="button" value="Search" onclick="codeLatLng()">
  </div>
  <div id="map_canvas"></div>
</body>
</html>